package org.gdpu.Service.Impl;

import org.gdpu.Service.ApplicationService;
import org.gdpu.base.DaoSupport;
import org.gdpu.model.Application;
import org.gdpu.model.ApplyState;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by HEWI2 on 2/17/14.
 */

@Service
@Transactional
public class ApplicationServiceImpl extends DaoSupport<ApplyState> implements ApplicationService {

    @Override
    public boolean checkApply(String applyStu) {

        Query query = em.createQuery("from Application a where a.applyStudent.studentId = ?1 and a.applyState in (0,1)");
        query.setParameter(1, Integer.valueOf(applyStu));
/*        query.setParameter(2,ApplyState.WAIT);
        query.setParameter(3,ApplyState.APPLY);*/
        return query.getResultList().size() > 0 ? false : true;
    }

    @Override
    public List<Application> findSureApply() {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("applyState", ApplyState.APPLY);
        return this.findByFields(Application.class, params);
    }
}
